import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///具体的orderList
class OrderListWidget extends StatefulWidget {
  @override
  _OrderListWidgetState createState() => _OrderListWidgetState();
}

class _OrderListWidgetState extends State<OrderListWidget> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(itemBuilder: (BuildContext context, int index) {
      return GestureDetector(
          onTap: () {
            // switch (model.scoutOrderList[index]?.investigator) {
            //   case "待定损":
            //     urlPush(context, "yuntu://scout_await_assessment");
            //     break;
            //   case "已定损":
            //     urlPush(context, "yuntu://scout_already_assessment");
            //     break;
            //   case "定损成功":
            //     urlPush(context, "yuntu://assessment_success");
            //     break;
            //   case "已撤案":
            //     urlPush(context, "yuntu://quash_case");
            //     break;
            //   case "维修完成":
            //     urlPush(context, "yuntu://complete_maintenance");
            //     break;
            //   case "维修中":
            //     urlPush(context, "yuntu://scout_in_maintenance");
            //     break;
            //   case "定损争议":
            //     urlPush(context, "yuntu://assessment_dispute");
            //     break;
            // }
          },
          child: _awaitLossAssessment());
    });
  }

  ///已确认,待定损  / 定损争议 / 已定损,维修中 / 维修完成,待赔付 / 已赔付 / 已退回
  Widget _awaitLossAssessment() {

    return Container(
      margin: EdgeInsets.only(
          left: setWidth(15), right: setWidth(15), top: setWidth(15)),
      decoration: BoxDecoration(
          color: Color(0xffF8F8F8), borderRadius: BorderRadius.circular(2)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          //处理编号
          _dealingNum(
              num:  "AE11232498",
              state: "已报案"),
          //车辆型号
          _carInfo(
              type: "奥迪A3",
              time: "2020-01-21 10:10"),
          //车主信息
          _carOwnerInfo("王宝强 苏A98U98"),
          //维修地点
          Container(
            margin: EdgeInsets.only(top: setWidth(17)),
            padding: EdgeInsets.only(left: setWidth(14), right: setWidth(14)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(
                        text: "维修地点:",
                        style: TextStyle(
                            color: Color(0xff999999), fontSize: setSp(14))),
                    WidgetSpan(
                        child: SizedBox(
                      width: setWidth(3),
                    )),
                    TextSpan(
                        text: "云途养护旗舰店",
                        style: TextStyle(
                            color: Color(0xff323232), fontSize: setSp(14))),
                  ])),
                ),
              ],
            ),
          ),
          SizedBox(
            height: setWidth(17),
          ),
          Container(
            height: setWidth(0.5),
            color: Color(0xffF0F0F0),
          ),
          Container(
            padding: EdgeInsets.only(left: setWidth(14), right: setWidth(14)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                _iconContent(
                    image: "scout_phone.png",
                    title: "致电车主",
                    phone: ""),
                Container(
                  width: setWidth(0.5),
                  height: setWidth(50),
                  color: Color(0xffF0F0F0),
                ),
                _iconContent(
                    image: "scout_call.png",
                    title: "致电维修店",
                    phone: "151515"),
                Container(
                  width: setWidth(0.5),
                  height: setWidth(50),
                  color: Color(0xffF0F0F0),
                ),
                _messageContent(image: "scout_im.png", title: "联系维修店"),
              ],
            ),
          )
        ],
      ),
    );
  }

  //处理编号
  Widget _dealingNum({String num, String state}) {
    return Container(
      padding: EdgeInsets.only(left: setWidth(14), right: setWidth(14)),
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(
                text: TextSpan(children: [
                  TextSpan(
                      text: "处理编号:",
                      style:
                      TextStyle(color: Color(0xff999999), fontSize: setSp(14))),
                  WidgetSpan(
                      child: SizedBox(
                        width: setWidth(3),
                      )),
                  TextSpan(
                      text: num,
                      style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(14))),
                ])),
          ),
          Container(
            child: Text(state,
                style:
                TextStyle(color: Color(0xffF74C31), fontSize: setSp(13))),
          )
        ],
      ),
    );
  }

  //车辆型号
  Widget _carInfo({String type, String time}) {
    return Container(
      padding: EdgeInsets.only(left: setWidth(14), right: setWidth(14)),
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(
                text: TextSpan(children: [
                  TextSpan(
                      text: "车辆型号:",
                      style:
                      TextStyle(color: Color(0xff999999), fontSize: setSp(14))),
                  WidgetSpan(
                      child: SizedBox(
                        width: setWidth(3),
                      )),
                  TextSpan(
                      text: type,
                      style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(14))),
                ])),
          ),
          Container(
            child: Text(time,
                style:
                TextStyle(color: Color(0xff999999), fontSize: setSp(13))),
          )
        ],
      ),
    );
  }

  //车主信息
  Widget _carOwnerInfo(String info) {
    return Container(
      padding: EdgeInsets.only(left: setWidth(14), right: setWidth(14)),
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(
                text: TextSpan(children: [
                  TextSpan(
                      text: "车主信息:",
                      style:
                      TextStyle(color: Color(0xff999999), fontSize: setSp(14))),
                  WidgetSpan(
                      child: SizedBox(
                        width: setWidth(3),
                      )),
                  TextSpan(
                      text: info,
                      style:
                      TextStyle(color: Color(0xff1666F1), fontSize: setSp(14))),
                ])),
          ),
        ],
      ),
    );
  }

  //图标
  Widget _iconContent({String image, String title, String phone}) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        callPhone(phone);
      },
      child: Row(
        children: [
          Container(
            width: setWidth(12.5),
            height: setWidth(13),
            child: Image.asset(
              "assets/images/$image",
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            width: setWidth(3),
          ),
          Container(
            child: Text(
              title,
              style: TextStyle(
                  color: Color(0xff323232),
                  fontSize: setSp(13),
                  fontWeight: FontWeight.w500),
            ),
          ),
        ],
      ),
    );
  }

  //图标
  Widget _messageContent({String image, String title}) {
    return Row(
      children: [
        Container(
          width: setWidth(16),
          height: setWidth(16),
          child: Image.asset(
            "assets/images/$image",
            fit: BoxFit.cover,
          ),
        ),
        SizedBox(
          width: setWidth(3),
        ),
        Container(
          child: Text(
            title,
            style: TextStyle(
                color: Color(0xff323232),
                fontSize: setSp(13),
                fontWeight: FontWeight.w500),
          ),
        ),
      ],
    );
  }
}
